package com.threeox.commonlibrary.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.LinearLayout;

import com.threeox.commonlibrary.entity.engine.model.layout.CommandMsg;

/**
 *
 * @ClassName: ModelButton
 *
 * @Description: Todo(模型的按钮)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/20 14:57
 *
 * @version 1.0
 */
public class ModelButton extends Button {

	/** 命令的消息 */
	private CommandMsg commandMsg;

	public ModelButton(Context context) {
		super(context);
	}

	public ModelButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ModelButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public CommandMsg getCommandMsg() {
		return commandMsg;
	}

	/**
	 * 设置按钮的消息
	 * 
	 * @param commandMsg
	 * @param onClick
	 * @return
	 */
	public ModelButton setCommandMsg(CommandMsg commandMsg, OnClickListener onClick) {
		this.commandMsg = commandMsg;
		
		this.setTag(commandMsg.getCommandTag());
		this.setTextColor(getContext().getResources().getColor(
				android.R.color.white));
		this.setText(commandMsg.getCommandText());
		this.setBackgroundResource(commandMsg.getCommandBgId());
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1);
		lp.setMargins(10, 10, 10, 5);
		this.setLayoutParams(lp);
		this.setOnClickListener(onClick);
		return this;
	}

}
